package ru.elteam.web.beans.request;

import ru.elteam.ejb.entities.User;
import ru.elteam.ejb.logic.UserMangementBean;
import ru.elteam.web.beans.session.UserBean;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.inject.Inject;
import javax.inject.Named;

/**
 * @author Nikita.Brazhnikov
 */
@Named("login")
@RequestScoped
public class UserLoginBean implements ActionListener {

	@Inject
	UserBean userBean;

	@EJB
	UserMangementBean loginBean;

	private String login;

	private String password;

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String doLogin() {
		User user = loginBean.getUser(login);
		userBean.setUpUser(user);
		return "";
	}

	public String doLogout() {
		userBean.dropUser();
		return "";
	}

	@Override
	public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
	}
}
